package com.example.getaudit.common.handle;

import com.example.getaudit.common.exception.BusinessException;
import com.example.getaudit.common.exception.CommonException;
import com.example.getaudit.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 当抛出这个异常时 会被ControllerAdvice拦截
 * ExceptionHandler (value = 类名.class)  指明要拦截的异常是哪个类
 */
@RestControllerAdvice
@Slf4j
@SuppressWarnings({"unchecked", "all"})
public class BaseExceptionHandler {

    /**
     * 拦截BaseException
     */
    @ExceptionHandler(BusinessException.class)
    public CommonResult handlerBaseException(CommonException e) {
        return CommonResult.error(e.getCode(), e.getMsg());
    }
}
